package com.ruoyi.supplier.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.supplier.domain.Supplier;
import com.ruoyi.supplier.domain.SupplierRating;
import com.ruoyi.supplier.mapper.SupplierMapper;
import com.ruoyi.supplier.mapper.SupplierRatingMapper;
import com.ruoyi.supplier.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-12
 */
@Service
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private SupplierMapper supplierMapper;

    @Autowired
    private SupplierRatingMapper supplierRatingMapper;

    /**
     * 查询供应商信息
     * 
     * @param id 供应商ID
     * @return 供应商信息
     */
    @Override
    public Supplier selectSupplierById(Long id) {
        return supplierMapper.selectSupplierById(id);
    }

    /**
     * 查询供应商列表
     * 
     * @param supplier 供应商信息
     * @return 供应商列表
     */
    @Override
    public List<Supplier> selectSupplierList(Supplier supplier) {
        List<Supplier> suppliers = supplierMapper.selectSupplierList(supplier);
        return suppliers;
    }

    /**
     * 新增供应商
     * 
     * @param supplier 供应商信息
     * @return 结果
     */
    @Override
    public int insertSupplier(Supplier supplier) {
        supplier.setCreateTime(DateUtils.getNowDate());
        return supplierMapper.insertSupplier(supplier);
    }

    /**
     * 修改供应商
     * 
     * @param supplier 供应商信息
     * @return 结果
     */
    @Override
    public int updateSupplier(Supplier supplier) {
        return supplierMapper.updateSupplier(supplier);
    }

    /**
     * 批量删除供应商
     * 
     * @param ids 需要删除的供应商ID
     * @return 结果
     */
    @Override
    public int deleteSupplierByIds(Long[] ids) {
        return supplierMapper.deleteSupplierByIds(ids);
    }

    /**
     * 查询供应商评分列表
     * 
     * @param supplierId 供应商ID
     * @return 供应商评分集合
     */
    @Override
    public List<SupplierRating> selectSupplierRatings(Long supplierId) {
        SupplierRating rating = new SupplierRating();
        rating.setSupplierId(supplierId);
        return supplierRatingMapper.selectSupplierRatingList(rating);
    }

    /**
     * 新增供应商评分
     * 
     * @param rating 供应商评分信息
     * @return 结果
     */
    @Override
    public int insertSupplierRating(SupplierRating rating) {
        rating.setCreateTime(DateUtils.getNowDate());
        return supplierRatingMapper.insertSupplierRating(rating);
    }
}
